package com.seanchenxi.gwt.wordpress.xmlrpc.service.model.handler;

import java.util.ArrayList;
import java.util.List;

import com.seanchenxi.gwt.wordpress.xmlrpc.service.model.impl.ModelFactory;
import com.seanchenxi.gwt.xmlrpc.client.impl.BaseResponseHandler;

public class CategoriesResponseHandler<T> extends BaseResponseHandler<ArrayList<T>>{
	
	@Override
	public ArrayList<T> handleResponse(String response) {
		Object object = super.handleResponse(response);
		
		if(ModelFactory.isNotList(object)) return null;
		
		ArrayList<T> categories = new ArrayList<T>();
		for(Object obj : (List<?>)object){
			T sc = ModelFactory.ToCategory(obj);
			if(sc!=null && !categories.contains(sc)){ 
				categories.add(sc);
			}
		}
			
		return categories;
	}
}
